/*
* @Author: wanghongfucoder
* @Date:   2017-04-12 09:59:11
* @Last Modified by:   wanghongfucoder
* @Last Modified time: 2017-04-12 10:08:38
*/

import java.util.ArrayList;
import java.util.List;
	
public class Cache {
	private  List<Service> services;
	public Cache(){
		services=new ArrayList<Service>();
	}

	public Service getService(String serviceName){
		for (Service service : services) {
			if (service.getName().equalsIgnoreCase(serviceName)) {
				System.out.println("Returning cached "+serviceName+"object");
				return service;
			}
		}
		return null;
	}

	public void addService(Service newService){
		boolean exists=false;
		for (Service service : services) {
			if (service.getName().equalsIgnoreCase(newService.getName())) {
				exists=true;
			}
		}
		if (!exists) {
			services.add(newService);
		}
	}
}